package com.base.common.action;

import com.base.common.bean.ActionResult;
import com.cjy.common.bean.OpAttributes;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import static com.base.common.GlobaConstants.*;
/**
 * 获取当前登陆用户权限信息
 * @author John
 * 时间：2014.09.22
 */
@Action("checkAuthorityAction")
@Results(
{ @Result(name = ASYNCHRONOUS,type = JSON,params =
{ ROOT, ACTION_RESULT_DATA, CONTENT_TYPE, CONTENT_TYPE_HTML })})

public class CheckAuthorityActionUtil extends AbstractBaseAction {
	private String auth_str;//权限字符串
	private String msg;//返回到前台的信息
	private String user_id;//当前登陆用户ID
	
	public String checkAuthority(){
		System.out.println("开始检测用户权限");
		Subject currentUser=SecurityUtils.getSubject();
		//判断是否有这个权限
		if(currentUser.isPermitted(auth_str)){
			actionResult = ActionResult.getActionResult(new OpAttributes(MSG, "repeat"));
		}else{
			actionResult = ActionResult.getActionResult(new OpAttributes(MSG, ""));
		}
		return returnType();
	}
	public String getAuth_str() {
		return auth_str;
	}
	public String getMsg() {
		return msg;
	}

	public String getUser_id() {
		return user_id;
	}
	public void setAuth_str(String auth_str) {
		this.auth_str = auth_str;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public void setUser_id(String user_id) {
		this.user_id = user_id;
	}

}
